package com.ysu.his.dispensary.controller;

import com.github.pagehelper.PageInfo;
import com.ysu.his.dto.PrescriptionDto;
import com.ysu.his.entity.prescription.Prescription;
import com.ysu.his.vo.DispensingVo;
import com.ysu.his.vo.PrescriptionVo;
import com.ysu.his.vo.RefundVo;
import com.ysu.his.dispensary.service.PrescriptionService;
import com.ysu.his.vo.common.Result;
import com.ysu.his.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处方相关接口控制器
 * 负责处方的分页查询、详情、发药、退药等接口
 */
@RestController
@RequestMapping("/api/dispensary/prescription")
public class PrescriptionController {
    @Autowired
    private PrescriptionService prescriptionService;

    /**
     * 分页条件查询处方
     * @param page 页码
     * @param limit 每页数量
     * @param prescriptionDto 查询条件
     * @return 分页结果
     */
    @GetMapping("/getPrescriptionByPage/{page}/{limit}")
    public Result getPrescriptionByPage(@PathVariable("page") Integer page,
                                        @PathVariable("limit") Integer limit,
                                        PrescriptionDto prescriptionDto) {
        PageInfo<Prescription> pageInfo = prescriptionService.getPrescriptionByPage(page, limit, prescriptionDto);
        return Result.ok(pageInfo);
    }

    /**
     * 根据处方id查询处方信息
     * @param id 处方ID
     * @return 处方详情
     */
    @GetMapping("/getPrescriptionById/{id}")
    public Result getPrescriptionById(@PathVariable("id") Long id) {
        PrescriptionVo prescriptionVo = prescriptionService.getPrescriptionById(id);
        return Result.ok(prescriptionVo);
    }

    /**
     * 发药
     * @param
     * @return 操作结果
     */
    @GetMapping("/dispensing/{prescriptionId}")
    public Result dispensing(@PathVariable("prescriptionId")Long prescriptionId) {
        prescriptionService.dispensing(prescriptionId);
        return Result.ok(null);
    }

    /**
     * 退药申请
     * @param id 处方ID
     * @return 操作结果
     */
    @GetMapping("/apply4Refund/{id}")
    public Result apply4Refund(@PathVariable("id") Long id) {
        prescriptionService.apply4Refund(id);
        return Result.ok(null);
    }
} 